package com.springStudy.context.annotation.conditional;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;

/**
 * 当Bean被Configuration 注解时才会被注入到容器中
 * 注释掉 getBean 方法上面的  @Conditional(MagicExistCondition.class) 发现 getBean 这个Bean无法注册到容器中
 */
@Configuration
@Conditional(MagicExistCondition.class)
@ComponentScan(value = "com.springStudy.context.annotation.conditional.*")
public class ConditionalDemo {
    public static void main(String[] args) {

        ApplicationContext context = new AnnotationConfigApplicationContext(ConditionalDemo.class);
        String[] beanDefinitionNames = context.getBeanDefinitionNames();

        System.out.println("-------------- bean name ---------------");
        for (String beanName : beanDefinitionNames) {
            System.out.println(beanName + " : " + context.getBean(beanName));
        }
    }

    @Bean
    @Conditional(MagicExistCondition.class)
    public String getBean(){
        return "aaaaaaaaaa";
    }
}
